package com.qf.controller;

import com.qf.pojo.BaseResp;
import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.utils.UplodUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.qf.pojo.BaseResp;
import com.qf.pojo.UserReq;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Controller
@RequestMapping(value = "/user")

public class UserController {
    @Autowired
    UserService userService;

    @Autowired
    UplodUtils uplodUtils;

    @PostMapping(value = "/del")
    @ResponseBody
    public BaseResp del(@RequestBody User user){
       return userService.del(user.getId());
    }

    @PostMapping(value = "/updatepassword")
    @ResponseBody
    public BaseResp updatepassword(@RequestBody UserReq userReq , HttpServletRequest request){
        return userService.updatepassword(userReq,request);
    }

    @PostMapping(value = "/update")
    @ResponseBody
    public BaseResp update(@RequestBody User user){
        return userService.update(user);
    }


    @PostMapping(value = "/findOne")
    @ResponseBody
    public BaseResp findOne(@RequestBody User user){
        return userService.findOne(user.getId());
    }

    @RequestMapping("/registry")
    @ResponseBody
    public BaseResp registry(@RequestBody UserReq userReq, HttpServletRequest request){
        return userService.registry(userReq,request);
    }

    @RequestMapping("/sendEmail")
    @ResponseBody
    public BaseResp sendEmail(@RequestBody Map map,HttpServletRequest request){
        return userService.sendEmail(map.get("email").toString(),request);
    }

    @RequestMapping("/login")
    @ResponseBody
    public BaseResp login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping(value = "/updateemail")
    @ResponseBody
    public BaseResp updateemail(@RequestBody Map map,HttpServletRequest request){
        return userService.updateemail(map.get("email").toString(),request);
    }

    @PostMapping(value = "/u")
    @ResponseBody
    public String uplod(@RequestParam("file") MultipartFile multipartFile){
        return uplodUtils.upload(multipartFile);
    }

    @PostMapping(value = "/getUser")
    @ResponseBody
    public BaseResp getUser(@RequestBody User user){
        return userService.getUser(user.getName());
    }

    @PostMapping(value = "/findphone")
    @ResponseBody
    public BaseResp findphone(@RequestBody Map map){
        return userService.findphone(map.get("phone").toString(),map.get("code").toString());
    }

}
